package com.miaoshare.app;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;


import org.greenrobot.eventbus.EventBus;

/**
 * Created by ${zxs}
 * on 2020/10/13
 * 向服务端发送消息
 */
public class HeartService extends Service {
    //Service启动时调用
//    PollingUtil pollingUtil;
    Runnable runnableTime;
    private int heartTime = 30000;

    private Handler mHandler = new Handler();

    private boolean isStop = false;

    @Override
    public void onCreate() {
        super.onCreate();
        Log.e("1111","HeartService onCreate");

        startk();
    }

    public void startk(){
        Log.e("1111","HeartService startk");
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                EventBus.getDefault().post(new ServiceEvent());
                if (!isStop){
                    startk();
                }
            }
        },5000);
    }

    @Override

    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;

    }

    //服务被关闭时调用
    @Override
    public void onDestroy() {
        isStop = true;
        super.onDestroy();
//        XLog.v("wang", "onDestroy 服务关闭时");
//        if (!Valid.isNullOrEmpty(pollingUtil)) {
//            pollingUtil.endPolling(runnableTime);
//        }
    }


}
